float2 HalfPixel;

int Radius;

texture Input;
sampler inputSampler = sampler_state
{
    Texture = <Input>;
    AddressU = Clamp;
    AddressV = Clamp;
    MagFilter = Linear;
    MinFilter = Linear;
};

struct ShaderData
{
    float4 Position : POSITION0;
    float2 TexCoord : TEXCOORD0;
};

ShaderData VertexShaderFunction(ShaderData input)
{
    return input;
}

float4 PixelShaderFunction(float2 screenCoord : TEXCOORD0) : COLOR0
{
    float result = 0.0;
    int r = min(Radius, 2);

    for (int i = -r + 1; i <= r; i++)
        for (int j = -r + 1; j <= r; ++j)
        {
            float2 offset = float2(HalfPixel * 2 * float2(i, j));
            result += tex2D(inputSampler, screenCoord + offset);
        }
    
    result /= (r * 2 - 1) * (r * 2 - 1);
    return result;
}

technique Technique1 <string Output="Output";>
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
